/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import request from '@/utils/request';

export async function getRegisterList(params: any) {
  return request('/jdk/League/merchantSearch', {
    method: 'POST',
    data: params,
  });
}

export async function getFranchiseeList(params: any) {
  return request('/jdk/League/search', {
    method: 'POST',
    data: params,
  });
}

export async function getFranchiseeShopList(params: any) {
  return request('/jdk/League/listStaff', {
    method: 'POST',
    data: params,
  });
}

export async function saveBind(params: any) {
  const apiList = {
    league: '/jdk/League/bind',
    chain: '/jdk/chain/bind',
  };
  const url = apiList[params.type];
  delete params.type;
  return request(url, {
    method: 'POST',
    data: params,
  });
}

export async function saveUnBind(params: any) {
  const apiList = {
    league: '/jdk/League/unbind',
    chain: '/jdk/chain/unbind',
  };
  const url = apiList[params.type];
  delete params.type;
  return request(url, {
    method: 'POST',
    data: params,
  });
}

export async function saveBlack(params: any) {
  return request('/jdk/League/black', {
    method: 'POST',
    data: params,
  });
}

export async function saveUnBlack(params: any) {
  return request('/jdk/League/unblack', {
    method: 'POST',
    data: params,
  });
}

export async function saveRemark(params: any) {
  return request('/jdk/League/remark', {
    method: 'POST',
    data: params,
  });
}

export async function oneClickRegister(params: any) {
  return request('/jdk/League/oneClickRegister', {
    method: 'POST',
    data: params,
  });
}

export async function getDetailData(params: any) {
  return request('/jdk/League/merchantDetail', {
    method: 'POST',
    data: params,
  });
}

export async function getTransportList(params: any) {
  return request('/jdk/shop/list', {
    method: 'POST',
    data: params,
  });
}

export async function addAccount(params: any) {
  return request('/jdk/delivery/addAccount', {
    method: 'POST',
    data: params,
  });
}

export async function bindKeruyun(params: any) {
  return request('/jdk/shop/bindKeruyun', {
    method: 'POST',
    data: params,
  });
}

export async function getCarryList(params: any) {
  return request('/jdk/League/getServiceFeeByMerchat', {
    method: 'POST',
    data: params,
  });
}

export async function getLogList(params: any) {
  return request('/jdk/League/getOperateRecord', {
    method: 'POST',
    data: params,
  });
}

export async function saveCarryPrice(params: any) {
  return request('/jdk/League/setServiceFeeByBrand', {
    method: 'POST',
    data: params,
  });
}

export async function getBrandList(params: any) {
  return request('/jdk/League/deliveryBrandList', {
    method: 'POST',
    data: params,
  }).then((res) => {
    const { data } = res;
    const brandData = data.map((item: { name: any; code: any }) => ({
      label: item.name,
      value: item.code,
    }));
    return brandData || [];
  });
}

export async function enableLeagueServiceFee(params: any) {
  return request('/jdk/League/enableLeagueServiceFee', {
    method: 'POST',
    data: params,
  });
}

// 是否允许聚单客商家开通飓风跑腿权限
export async function setRiderSwitch(params: any) {
  return request('/jdk/League/setRiderSwitch', {
    method: 'POST',
    data: params,
  });
}

export async function allowLogin(params: any) {
  return request('/jdk/League/allowLogin', {
    method: 'POST',
    data: params,
  });
}

export async function setAllowDeliveryStatus(params: any) {
  return request('/jdk/League/allowSetDeliveryStatus', {
    method: 'POST',
    data: params,
  });
}

/**
 *
 * @description 获取加盟商/商家平台运力加价
 * @param params
 * @returns
 */
export async function getDelivery(params: any) {
  const { league_id, user_id, type = 'league' } = params;
  let data: any = { league_id };
  let url = '/jdk/League/getDeliveryMarkup';
  if (type === 'shop') {
    data = { user_id };
    url = '/jdk/League/getMerchantPlatformMarkup';
  }
  return request(url, {
    method: 'POST',
    data,
  });
}

/**
 *
 * @description 设置加盟商/商家平台运力加价
 * @param params
 * @returns
 */
export async function setDelivery(params: any) {
  const { league_id, user_id, type = 'league', ...rest } = params;
  let data: any = { league_id };
  let url = '/jdk/League/setDeliveryMarkup';
  if (type === 'shop') {
    data = { user_id };
    url = '/jdk/League/setMerchantPlatformMarkup';
  }
  return request(url, {
    method: 'POST',
    data: {
      ...rest,
      ...data,
    },
  });
}

export async function setDeliveryStatus(params: any) {
  return request('/jdk/League/setDeliveryStatus', {
    method: 'POST',
    data: params,
  });
}

// 设置顺丰模式
export async function setShunFun(params: any) {
  const apiList = {
    league: '/jdk/League/setLeagueShunfen', //  聚单客服务商
    merchant: '/jdk/League/setMerchantShunfen', // 聚单客商家
  };
  const url = apiList[params.type] || '';
  delete params.type;
  return request(url, {
    method: 'POST',
    data: params,
  });
}

// 重置顺丰模式
export async function resetShunFun(params: any) {
  const apiList = {
    league: '/jdk/League/resetLeagueShunfen', //  聚单客服务商
    merchant: '/jdk/League/resetMerchantShunfen', // 聚单客商家
  };
  const url = apiList[params.type] || '';
  delete params.type;
  return request(url, {
    method: 'POST',
    data: params,
  });
}
